package com.qkl.xiatang.app.web.controller;

import com.qkl.xiatang.app.service.impl.WeatherService;
import com.qkl.xiatang.app.utils.ErrorCodeUtils;
import com.qkl.xiatang.app.utils.Result;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("{app.baseURL}")
@Slf4j
public class CommonController {

    @Autowired
    private WeatherService weatherService;

    /**
     * 天气查询
     * @param params
     * @return
     */
    @GetMapping("/queryWeather")
    public Result queryWeather(@RequestParam Map<String,Object> params) {
        String lng = StringUtils.trimToEmpty((String) params.get("lng"));
        String lat = StringUtils.trimToEmpty((String) params.get("lat"));
        String days = StringUtils.trimToEmpty((String) params.get("days"));
        if(StringUtils.isAnyEmpty(days)){
            return Result.error(ErrorCodeUtils.PARAM_EMPTY, ErrorCodeUtils.PARAM_EMPTY_MSG);
        }
        return ControllerHelper.toQueryResult(weatherService.queryWeather(lng,lat,days));
    }



}
